library(tidyverse)

theme_set(theme_bw())

load("data/processed/pwdprotect_effect_on_primary.RData")

fct_1_ordered <- 
  c(
    # `new label` = 
    # "old label"
    `Eigenvector centrality, MeetUp` = 
      "meetup_eigenvector_centrality",
    `Eigenvector centrality, M5S forum` = 
      "forum_eigenvector_centrality",
    `Out degree centrality, Facebook` = 
      "facebook_out_degree_centrality",
    `In the same community as the party leader` = 
      "communities_usergiant_leader",
    `Page rank, giant component` = 
      "page_rank_usergiant")

map(c('output/figures/figure_6.eps', 'output/figures/figure_6.png'), 
    ~ ggsave(.x, plot =
               df %>%
               dplyr::select(giantPredictions, 
                             meetup_eigenvector_centrality, 
                             forum_eigenvector_centrality,
                             facebook_out_degree_centrality,
                             communities_usergiant_leader,
                             page_rank_usergiant) %>%
               tidyr::pivot_longer(cols = 
                                     meetup_eigenvector_centrality:page_rank_usergiant) %>%
               dplyr::mutate(name = 
                               factor(forcats::fct_recode(name, !!!fct_1_ordered),
                                      levels = names(fct_1_ordered),
                                      ordered = T),
                             value = 
                               factor(forcats::fct_recode(value,
                                                          `not present` = "not_present"), 
                                      levels = c("no", "not present", "yes", "lower third", 
                                                 "mid third", "upper third"),
                                      ordered = T)) %>%
               
               ggplot(aes(x=value, y=giantPredictions)) +
               geom_boxplot() +
               facet_wrap("name", scales = "free_x") +
               labs(y = "predictions", x = NULL),
             
             
             width = 25, height = 18, units = 'cm'
    )
)